<script type="text/javascript">
 	jQuery(function(){
		$('.ajax-link').click(function(e){
			e.preventDefault();
			var element = this;
			$.ajax({
				url: $(element).prop('href'),
				success: function(data){
					$(element).removeClass('btn-danger');
					$(element).text('<?php echo __('Marcar coordenador');?>');
					$(element).prop('href', '#aviso-reload');
					$(element).attr('data-toggle', "modal");
				}
			});
 		});
		$('.ajax-post').click(function(e){
			e.preventDefault();
			var element = this;
			$.ajax({
				url: $(element).prop('href'),
				type: 'POST',
				data: {CoordenadorTrabalho: {categoria_id: "<?php echo $categoria;?>"}},
				success: function(data){
					$(element).addClass('btn-danger');
					$(element).text('<?php echo __('Desmarcar coordenador');?>');
					$(element).prop('href', '#aviso-reload');
					$(element).attr('data-toggle', "modal");
				}
			});
 		});
 		$('#mostrar-coordenadores').click(function(){
 			if($(this).hasClass('active')){
 				$('.botao > :not(a.btn-danger)').parent().parent().show();
 			}
 			else{
				$('.botao > :not(a.btn-danger)').parent().parent().hide();
 			}
 			$(this).button('toggle');
 		});
 	});
</script>
<h2><?php echo __('Coordenadores de Trabalhos').' '.__('Categoria').': '.$categorias[$categoria]; ?></h2>
	<div class="btn-group">
	<?php echo $this->Html->link(__('Mostrar apenas coordenadores'), '#', array('class'=>'btn btn-default', 'id'=>'mostrar-coordenadores'));?>
	<?php echo $this->Html->link(__('Voltar'), array('action'=>'index'), array('class'=>'btn btn-default'));?>
	</div>
	<br><br><br>
<?php if(!empty($usuarios)){?>
<table class="table">
<tr>
		<th><?php echo __('Usuario');?></th>
		<th></th>
</tr>
<?php foreach ($usuarios as $key=>$item): ?>
<tr>
	<td><?php echo ($item); ?>&nbsp;</td>
	<td class="botao">
		<?php if($id = array_search($key, $usuarios_coordenadores)){?>
			<?php echo $this->Html->link(__('Desmarcar coordenador'), array('controller' => 'coordenador_trabalhos', 'action' => 'delete', $id, $key), array('class'=>'btn btn-danger ajax-link')); ?>
		<?php }else{?>
			<?php echo $this->Html->link(__('Marcar coordenador'), array('controller' => 'coordenador_trabalhos', 'action' => 'add', $key), array('class'=>'btn ajax-post')); ?>
		<?php }?>
	</td>
</tr>
<?php endforeach; ?> 
</table>
<?php }else{ ?>
	<?php echo __('Sem usuários nessa categoria');?>	
<?php }?>
<div id="aviso-reload" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
    <h3 id="myModalLabel">Aviso</h3>
  </div>
  <div class="modal-body">
    <p><?php echo __('Você deve atualizar a página antes de efetuar essa operação')?></p>
  </div>
  <div class="modal-footer">
  	<?php echo $this->html->link(__('Atualizar [F5]'), '', array('class'=>'btn btn-primary'));?>
    <button class="btn" data-dismiss="modal" aria-hidden="true"><?php echo __('Fechar');?></button>
  </div>
</div>